<?php

namespace User\Form;

use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use \Zend\Form\Form;

class UserFormFactory implements FactoryInterface {

    public function createService(ServiceLocatorInterface $serviceLocator) {
        $form = new Form('user');
        $form->setAttribute('method', 'post');

        $form->add(array(
            'name' => 'id',
            'type' => 'hidden',
        ));
        $form->add(array(
            'name' => 'login',
            'type' => 'text',
            'options' => array(
                'label' => 'Login',
            ),
        ));
        $form->add(array(
            'name' => 'password',
            'type' => 'text',
            'options' => array(
                'label' => 'Password',
            ),
        ));
        $roleRepository = $serviceLocator->get('User\Repository\RoleRepository');
        $roles = $roleRepository->getRoles();
//        $roles = array_filter($roleRepository->getRoles(), function($role) {
//                    return $role !== 'admin';
//                });
        $form->add(array(
            'name' => 'role',
            'type' => 'select',
            'options' => array(
                'label' => 'Role',
                'empty_option' => 'Choose a role',
                'value_options' => array_combine($roles, $roles),
            ),
        ));
        $form->add(array(
            'name' => 'firstName',
            'type' => 'text',
            'options' => array(
                'label' => 'First Name',
            ),
        ));
        $form->add(array(
            'name' => 'lastName',
            'type' => 'text',
            'options' => array(
                'label' => 'Last Name',
            ),
        ));
        $form->add(array(
            'name' => 'submit',
            'type' => 'submit',
            'attributes' => array(
                'value' => 'Go',
                'id' => 'submitbutton',
            ),
        ));

        $inputFilter = $serviceLocator->get('User\Form\UserFilter');
        $form->setInputFilter($inputFilter);
        
        $form->setHydrator(new \Zend\Stdlib\Hydrator\ClassMethods(false));

        return $form;
    }

}